import babelpolyfill from 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
import 'element-theme-chalk';
import 'element-ui/lib/theme-chalk/index.css';

// import 'element-theme-chalk';
//import './assets/theme/theme-green/index.css'
import VueRouter from 'vue-router'
import store from './vuex/store'
import Vuex from 'vuex'
//import NProgress from 'nprogress'
//import 'nprogress/nprogress.css'
import axios from 'axios'
import Qs from 'qs'

import routes from './routes'
//import Mock from './mock'
//Mock.bootstrap();
import 'font-awesome/css/font-awesome.min.css'
import QRCode from 'qrcodejs2';
import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
Vue.use(VueQuillEditor)//富文本  像textarea 可以插图片

Vue.use(ElementUI)
Vue.use(VueRouter)
Vue.use(Vuex)
Vue.prototype.qrCode

//NProgress.configure({ showSpinner: false });
//线上
axios.defaults.baseURL = 'http://47.104.89.247:6001/' 
//本地
//axios.defaults.baseURL = 'http://192.168.0.106:8840' 
// axios.defaults.baseURL = 'http://127.0.0.1:6001/' 
//axios.defaults.baseURL = 'http://47.99.162.11:8848/kh/'

Vue.prototype.$http= axios
Vue.prototype.qs = Qs//把参数格式化

const router = new VueRouter({
  routes
})

// router.beforeEach((to, from, next) => {
//   //NProgress.start();
//   if (to.path == '/login') {
//     sessionStorage.removeItem('user');
//   }
//   let user = JSON.parse(sessionStorage.getItem('user'));
//   if (!user && to.path != '/login') {
//     next({ path: '/login' })
//   } else {
//     next()
//   }
// })
router.beforeEach((to, from, next) => {
  if (to.path == '/login') {
    // sessionStorage.removeItem('user');
    // sessionStorage.removeItem('id');
    // sessionStorage.removeItem('type');
  }
  let user = JSON.parse(sessionStorage.getItem('user'));
  if (!user && to.path != '/login') {
    next({ path: '/login' })
  } else {
    next()
  }
})

//router.afterEach(transition => {
//NProgress.done();
//});

new Vue({
  //el: '#app',
  //template: '<App/>',
  router,
  store,
  //components: { App }
  render: h => h(App)
}).$mount('#app')

